/**
 * Created by loso on 2017/3/27.
 */
public class _7_ReverseInteger {

    public static void main(String[] args) {
        _7_ReverseInteger a = new _7_ReverseInteger();
        System.out.println(a.reverse(-123));
    }

    public int reverse(int x) {
        long out = 0;
        while (x!=0){
            out = out*10 + (x%10);
            x = x/10;
            if (out>Integer.MAX_VALUE || out<Integer.MIN_VALUE){
                return 0;
            }
        }
        return (int) out;
    }

}
